package com.zy.news.controller;

import com.zy.news.entity.News;
import com.zy.news.mapper.NewsMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "新闻管理")
@RestController
@RequestMapping("news")
public class NewsController {

    @Resource
    private NewsMapper newsMapper;

    @ApiOperation(value = "查询新闻列表")
    @GetMapping
    public List<News> findAll(){
        return newsMapper.selectList(null);
    }

    @ApiOperation(value = "查询新闻详情")
    @GetMapping("/findOne")
    public News findById(int id){
        return newsMapper.selectById(id);
    }

    @ApiOperation(value = "发布新闻")
    @PostMapping
    public int add(@RequestBody News news){
        return newsMapper.insert(news);
    }

    @ApiOperation(value = "编辑新闻")
    @PutMapping
    public int edit(@RequestBody News news){
        return newsMapper.updateById(news);
    }

    @ApiOperation(value = "删除新闻")
    @DeleteMapping
    public int del(int id){
        return newsMapper.deleteById(id);
    }
}
